<?php
    // +----------------------------------------------------------------------
    // | shop模型
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------
    namespace app\model\store;

    class OrderExpress extends Common
    {


        //获取器
        public function getDistrictTextAttr($value, $data)
        {
            return implode('-', json_decode($data['district'], true));
        }

        public function order()
        {
            return $this->belongsTo(Order::class);
        }

        public function expressCompany()
        {
            return $this->belongsTo(ExpressCompany::class);
        }

        /**
         * 关联信息
         */
        public function from()
        {
            // 选择正常物流公司、无需派送信息，则关联卖家地址。
            // 如果选择自行配送，可以关联派送员信息
            if (isset($this->express_id) && $this->express_id == -1) {
                return $this->belongsTo('Member');
            } else {
                return $this->belongsTo('\app\seller\model\StoreAddress', 'from_id', 'id');
            }
        }

        // 类型转换
        protected $type = [
            'context' => 'array',
            'district' => 'array'
        ];
    }
